﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Com.CMS263.Util;
using Com.CMS263.PO;
using Com.CMS263.BLL;
using System.IO;

namespace Com.CMS263.Web.manage.GuestManage
{
    public partial class stu_add : System.Web.UI.Page
    {
        StudentInfoBLL sibll = new StudentInfoBLL();
        protected void Page_Load(object sender, EventArgs e)
        {
            
           
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            string realname = StringUtil.checkStr(Request["txtRealName"]);
            if (string.IsNullOrEmpty(realname))
            {
                StringUtil.Alert("请输入姓名", "-1");
            }
            string classname = StringUtil.checkStr(Request["txtClassName"]);
            if (string.IsNullOrEmpty(classname))
            {
                StringUtil.Alert("请输入班级", "-1");
            }
            string stunum = StringUtil.checkStr(Request["txtStuNum"]);
            if (string.IsNullOrEmpty(stunum))
            {
                StringUtil.Alert("请输入学号", "-1");
            }
            string username = StringUtil.checkStr(Request["txtUserName"]);
            if (string.IsNullOrEmpty(username))
            {
                StringUtil.Alert("请输入登录名", "-1");
            }
            if (sibll.isExist(username))
            {
                StringUtil.Alert("登录名已经存在,请更换", "-1");
            }
            string userpass = StringUtil.checkStr(Request["txtUserPass"]);
            if (string.IsNullOrEmpty(userpass))
            {
                StringUtil.Alert("请输入密码", "-1");
            }
            StudentInfo si = new StudentInfo();
            si.AddDate = DateTime.Now;
            si.Age = StringUtil.checkStr(Request["txtAge"]);
            si.ClassName = classname;
            
            si.ParentMobilePhone = StringUtil.checkStr(Request["txtPhone"]);
            si.RealName = realname;
            si.StuNum = stunum;
            si.UserName = username;
            si.UserPass = userpass;
            si.TeacherEmail = StringUtil.checkStr(Request["txtTeacherEmail"]);
            si.TeacherMessage = Request["txtTeacherMessage"];
            string strDay = DateTime.Now.ToString("yyyy-MM-dd");
            string savePath = Server.MapPath("/ArtUpFile/" + strDay);
            if (!Directory.Exists(savePath))
            {
                Directory.CreateDirectory(savePath);
            }
            HttpPostedFile hpf = Request.Files["txtHeadImage"];
            
            if (hpf.ContentLength < 5)
            {
                si.HeadImage = "";
            }
            else
            {

                si.HeadImage = strDay + "/" + UpLoadFileUtil.UpLoadFile(Request.Files["txtHeadImage"], savePath, "1");
            }
            sibll.entity = si;
            if (sibll.Add())
            {
                StringUtil.Alert("添加成功", "stu_list.aspx");
            }


        }
        
    }
}
